//
//  ZKVCSubscribe.m
//  ZAKER
//
//  Created by Anyfish002 on 16/2/16.
//  Copyright © 2016年 yaohongchao. All rights reserved.
//

#import "ZKVCSubscribe.h"
#import "ZKVSubscribeCell.h"
#import "ZKCollectionViewFlowLayout.h"
#import "ZKVCRecommend.h"

@interface ZKVCSubscribe ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
@property(nonatomic,weak) UICollectionView *collctionView;
@end

@implementation ZKVCSubscribe

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setup];
    // Do any additional setup after loading the view.
}

-(void)setup{
    [self.navigationItem setTitle:@"订阅"];
//    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//    [btn setImage:[UIImage imageNameFromeBundle:@"life_my_account"] forState:UIControlStateNormal];
//    [btn addTarget:self action:@selector(leftClicked) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:btn];
//    [self.navigationItem setLeftItem:item];
    
    
//    [self.navigationItem setLeftItem:@[@"返回"] imageNamed:@[@"addRootBlock_toolbar_return"] block:^(NSInteger itemIndex) {
//        NSLog(@"%d",itemIndex);
//    }];
    WS(weakSelf);
    [self.navigationItem setLeftItem:@[@""] imageNamed:@[@"life_my_account"] block:^(NSInteger itemIndex) {
        [weakSelf.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
    }];
    
    [self.navigationItem setRightItem:nil imageNamed:@[@"ExploreSearchButton"] block:^(NSInteger itemIndex) {
        ZKVCRecommend *zkRecommend = [[ZKVCRecommend alloc]init];
        [weakSelf.navigationController pushViewController:zkRecommend animated:YES];
    }];
    
//    UIButton  *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 30, 30)];
//    [btn addTarget:self action:@selector(rightClicked) forControlEvents:UIControlEventTouchUpInside];
//    [btn setImage:[UIImage imageNameFromeBundle:@"ExploreSearchButton"] forState:UIControlStateNormal];
//    UIBarButtonItem *item=[[UIBarButtonItem alloc]initWithCustomView:btn];
//    [self.navigationItem setRightBarButtonItem:item];
    
    ZKCollectionViewFlowLayout *layout = [[ZKCollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;//滚动方向
    layout.minimumLineSpacing = 0;//行间距(最小值)
    layout.minimumInteritemSpacing = 0;//item间距(最小值)
//    layout.itemSize = CGSizeMake(SCREEN_WIDTH/3, SCREEN_WIDTH/3);
    UICollectionView *collctionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - kNavigationBar_Height - kTabBar_Height) collectionViewLayout:layout];
  
    collctionView.backgroundColor = [UIColor bgColor];
    [collctionView registerClass:[ZKVSubscribeCell class] forCellWithReuseIdentifier:@"reuseCell"];
    [collctionView registerClass:[ZKVSubscribeHeader class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerReuse"];
    collctionView.delegate = self;
    collctionView.dataSource = self;
    [self.view addSubview:collctionView];
    [collctionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.right.equalTo(self.view);
    }];
    self.collctionView = collctionView;
    
}

-(void)leftClicked{
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}

-(void)rightClicked{
    ZKVCRecommend *zkRecommend = [[ZKVCRecommend alloc]init];
//    [zkRecommend setHidesBottomBarWhenPushed:YES];
    [self.navigationController pushViewController:zkRecommend animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark UICollectionViewDataSource UICollectionViewDelegate

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 20;
}

// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    ZKVSubscribeCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseCell" forIndexPath:indexPath];
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(SCREEN_WIDTH/3, SCREEN_WIDTH/3);
}

- (CGSize)collectionView:(UICollectionView *)collectionView sizeForLargeItemsInSection:(NSInteger)section;{
    return CGSizeMake(SCREEN_WIDTH/3, SCREEN_WIDTH/3);
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{
    ZKVSubscribeHeader *header = nil;
    if([kind isEqualToString:UICollectionElementKindSectionHeader]){
         header = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"headerReuse" forIndexPath:indexPath];
        header.scrollView.autoScrollTimeInterval = 5;
        header.scrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        header.scrollView.imageURLStringsGroup = @[@"http://fujian.86516.com/forum/201209/28/16042484m9y9izwbrwuixj.jpg",
                                      @"http://www.pp3.cn/uploads/allimg/111110/15594T106-10.jpg",
                                      @"http://www.pp3.cn/uploads/allimg/111112/110G31K5-6.jpg"];
        header.scrollView.titlesGroup = @[@"测试测试测试测试1",@"测试测试测试测试2",@"测试测试测试测试3"];
    }
    return header;
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{
    return CGSizeMake(SCREEN_WIDTH, 170);
}
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}


@end
